package org.company.earth.thread;

import java.util.concurrent.CountDownLatch;

import org.company.earth.service.ITaskService;

/**
 * CountDownLatch Runnable程序
 * @author hucw
 *
 */
public class CountRunnable implements Runnable{
    
    private CountDownLatch countDown;
    
    private ITaskService task;
    
    public CountRunnable(ITaskService task,CountDownLatch countDown) {
        this.countDown = countDown;
        this.task = task;
    }
    
    public CountRunnable(ITaskService task) {
        this.task = task;
    }
    
    @Override
    public void run() {
        try{
            task.execute();
        } finally {
            if(countDown != null) {
                countDown.countDown();
            }
        }
    }
}
